package com.fhz.day005

import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

/**
 * 时间:2021/10/19
 * @author msfeng
 * 简述: TODO
 */
class MyMigration(f:Int ,t:Int) : Migration(f,t) {

    override fun migrate(database: SupportSQLiteDatabase) {
        //  创建新的临时表
        database.execSQL( "CREATE TABLE users_new (id INTEGER not null, name TEXT not null, age INTEGER not null, PRIMARY KEY(id))" )
        // 复制数据
        database.execSQL( "INSERT INTO users_new (id, name, age) SELECT id, name, age FROM User" )
        // 删除表结构
        database.execSQL( "DROP TABLE user" )
        // 临时表名称更改
        database.execSQL( "ALTER TABLE users_new RENAME TO User" )
    }
}